#include <2025Linux.h>
int main(int argc, char *argv[])
{
    // ./01_find_file dir1 file1
    ARGS_CHECK(argc,3);
    // 切换当前工作目录
    int ret = chdir(argv[1]);
    ERROR_CHECK(ret,-1,"chdir");
    // 创建目录流
    DIR *dirp = opendir("."); //因为当前目录已经变了
    ERROR_CHECK(dirp,NULL,"opendir");
    struct dirent *direntp;
    int flag = 0; //指示是否存在同名的文件
    while((direntp = readdir(dirp)) != NULL){
        //printf("filename = %s\n", direntp->d_name);
        if(strcmp(argv[2],direntp->d_name) == 0){
            flag = 1;
            break;
        }
    }
    if(flag == 1){
        printf("Found!\n");
        char path[1024] = {0};
        sprintf(path,"%s/%s",getcwd(NULL,0),argv[2]);//把当前工作目录 和 / 和文件名拼接在一起
        printf("path = %s\n", path);
    }
    else{
        printf("Not found!\n");
    }
    return 0;
}

